Skip to content

test(pgshare): extract shared db-acquisition + schema-isolation core (RIG-2903) - #704

Merged
mattwilkinsonn merged 1 commit into
mainfrom
compass/rig-2903-pgshare-extract
Aug 28, 2026
Merged

test(pgshare): extract shared db-acquisition + schema-isolation core (RIG-2903)#704
mattwilkinsonn merged 1 commit into
mainfrom
compass/rig-2903-pgshare-extract

Conversation

@rigel-mintaka

Copy link
Copy Markdown
Contributor

T1 of the Go test-harness-tiers consolidation (design RIG-2742, #684). Extracts the one copy of the real-Postgres acquisition policy + per-test schema isolation out of internal/pgtest into a new shared internal/pgshare package, so the suite-postgres lanes (T2+) can build on the same core without an import cycle.

What moves

internal/pgshare/pgshare.go (build tag (pgtest || podman) && unix) holds the acquisition policy + schema isolation verbatimdecideDSNSource + the 5 sources, containerCLI, startContainer, removeContainerArgs, publishedPort, waitReady, schemaSeq, withSearchPath (incl. the existing-options panic guard) — exposed as the record's three produced interfaces: AcquireDSN(t), IsolatedSchemaDSN(t, dsn), StartSuitePostgres(tb, stateDir, sockDir, port), plus the TB-free StartSuitePostgresMain variant for TestMain (both delegate to one unexported bring-up body).

internal/pgtest/pgtest.go becomes a thin delegator: RequireDSN now returns pgshare.AcquireDSN(t); its exported surface (DSNEnvVar/UseContainerEnvVar/RequireLiveEnvVar + RequireDSN) is byte-for-byte unchanged, so none of the 30 integration call-sites move.

The three white-box unit tests of the extracted internals (TestDecideDSNSource, TestRemoveContainerArgsCarriesVolumesFlag, TestThrowawayContainerLeavesNoDanglingVolume) move with their code into pgshare_test.go, names/assertions byte-identical; a new TestStartSuitePostgresMainErrors covers the TB-free error paths (empty state dir, binary-not-on-PATH).

Verification

gofmt clean; go build ./... clean; go vet -tags 'pgtest unix' clean across pgshare, pgtest, and the store/board/server consumers; go test -tags 'pgtest unix' ./internal/pgshare/ green (all moved tests run, container test spins a real throwaway Postgres).

Spec-impact: none. Refs RIG-2903

Co-authored-by: Matt Wilkinson matt@rigel.build

@linear-code

linear-code Bot commented Aug 28, 2026

Copy link
Copy Markdown

RIG-2903

@rigel-mintaka
rigel-mintaka marked this pull request as draft August 28, 2026 03:30
@github-actions

github-actions Bot commented Aug 28, 2026

Copy link
Copy Markdown

Compass engineering docs preview: https://compass-rig-2903-pgshare-ext.compass-eng-docs.pages.dev

Deployed from compass/rig-2903-pgshare-extract at a1bbed9.

@rigel-mintaka
rigel-mintaka force-pushed the compass/rig-2903-pgshare-extract branch from ee26f85 to 46f8672 Compare August 28, 2026 03:53
…(RIG-2903)

T1 of the Go test-harness-tiers consolidation (design RIG-2742, #684). Extracts the one copy of the real-Postgres acquisition policy + per-test schema isolation out of `internal/pgtest` into a new shared `internal/pgshare` package, so the suite-postgres lanes (T2+) can build on the same core without an import cycle.

## What moves

`internal/pgshare/pgshare.go` (build tag `(pgtest || podman) && unix`) holds the acquisition policy + schema isolation **verbatim** — `decideDSNSource` + the 5 sources, `containerCLI`, `startContainer`, `removeContainerArgs`, `publishedPort`, `waitReady`, `schemaSeq`, `withSearchPath` (incl. the existing-`options` panic guard) — exposed as the record's three produced interfaces: `AcquireDSN(t)`, `IsolatedSchemaDSN(t, dsn)`, `StartSuitePostgres(tb, stateDir, sockDir, port)`, plus the TB-free `StartSuitePostgresMain` variant for TestMain (both delegate to one unexported bring-up body).

`internal/pgtest/pgtest.go` becomes a thin delegator: `RequireDSN` now returns `pgshare.AcquireDSN(t)`; its exported surface (`DSNEnvVar`/`UseContainerEnvVar`/`RequireLiveEnvVar` + `RequireDSN`) is **byte-for-byte unchanged**, so none of the 30 integration call-sites move.

The three white-box unit tests of the extracted internals (`TestDecideDSNSource`, `TestRemoveContainerArgsCarriesVolumesFlag`, `TestThrowawayContainerLeavesNoDanglingVolume`) move with their code into `pgshare_test.go`, names/assertions byte-identical; a new `TestStartSuitePostgresMainErrors` covers the TB-free error paths (empty state dir, binary-not-on-PATH).

## Verification

gofmt clean; `go build ./...` clean; `go vet -tags 'pgtest unix'` clean across pgshare, pgtest, and the store/board/server consumers; `go test -tags 'pgtest unix' ./internal/pgshare/` green (all moved tests run, container test spins a real throwaway Postgres).

Spec-impact: none. Refs RIG-2903

Co-authored-by: Matt Wilkinson <matt@rigel.build>
@rigel-mintaka
rigel-mintaka force-pushed the compass/rig-2903-pgshare-extract branch from 46f8672 to a1bbed9 Compare August 28, 2026 04:07
@rigel-mintaka
rigel-mintaka marked this pull request as ready for review August 28, 2026 05:09
@mattwilkinsonn
mattwilkinsonn merged commit 05b6d1d into main Aug 28, 2026
13 checks passed
@mattwilkinsonn
mattwilkinsonn deleted the compass/rig-2903-pgshare-extract branch August 28, 2026 17:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants